package com.t2t.top.gc;

/**
 *  VM Args:-verbose:gc -XX:+PrintGCDetails
 */
public class RefrenceCountingGC {
    public Object instance;
    private static final int _1MB = 1024 * 1024;

    private byte[] bigSize = new byte[2 * _1MB];

    public static void main(String[] args) throws InterruptedException {
        RefrenceCountingGC a = new RefrenceCountingGC();
        RefrenceCountingGC b = new RefrenceCountingGC();
        RefrenceCountingGC c = new RefrenceCountingGC();
        a.instance = b;
        b.instance = a;

        System.out.println("1 sleep 60s");
        Thread.sleep(60 * 1000);
        a = null;
        System.out.println(b.instance);
        //b = null;

        System.gc();

        System.out.println("2 sleep 60s");
        Thread.sleep(60 * 1000);
        System.out.println(b.instance);
        System.out.println("OK");
    }
}
